package com.algorithm.learning.base.二叉树;

/**
 * @program: algorithm-learning
 * @description:
 * @author: YuKai Fan
 * @create: 2024/8/23 23:29
 **/
public class 获取树的最大深度 {

    public static class Node {
        private Node left;
        private Node right;
        private int value;

        public Node(int value) {
            this.value = value;
        }
    }

    /**
     * 获取树的最大深度
     * @param root
     * @return
     */
    public static int getMaxDepth(Node root) {
        if (root == null) {
            return 0;
        }
        return Math.max(getMaxDepth(root.left), getMaxDepth(root.right)) + 1;
    }

    public static void main(String[] args) {
        Node root = new Node(1);
        root.left = new Node(2);
        root.right = new Node(3);
        root.left.left = new Node(4);
        root.left.right = new Node(5);
        root.right.left = new Node(6);
        root.right.left.left = new Node(6);
        root.right.left.right = new Node(6);
        System.out.println(getMaxDepth(root));
    }
}
